package servlet;

import model.Order;
import model.User;
import service.OrderService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "order_list",urlPatterns = "/order_list")
public class OrderListServlet extends HttpServlet {
    private OrderService oService = new OrderService();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User user = (User) req.getSession().getAttribute("user");
        if (user == null){
            req.setAttribute("failMsg","请先登录，登陆后方可查看订单信息！");
            req.getRequestDispatcher("/user_login.jsp").forward(req,resp);
        } else {
            List<Order> list = oService.selectOrder(user.getId());
            req.setAttribute("orderList",list);
            req.getRequestDispatcher("order_list.jsp").forward(req,resp);
        }
    }
}
